package study.springboot.mvc.controller.rest;

import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import study.eggs.result.Result;
import study.eggs.result.Results;

import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/rest")
public class GetController {

    @RequestMapping("/get")
    public Result getForObject(String name, Integer age) {
        log.info("name= {}, age= {}", name, age);
        Map<String, Object> data = Maps.newHashMap();
        if(1==1)
            throw new RuntimeException("ssssssssssssssss");
        return Results.ok(data);
    }

    @RequestMapping("/getWithHeader")
    public Result getWithoutHeader(String name, Integer age,
                                   @RequestHeader("X-Trace-Key") String traceKey) {
        log.info("name= {}, age= {}", name, age);
        log.info("traceKey= {}", traceKey);
        Map<String, Object> data = Maps.newHashMap();
        return Results.ok(data);
    }
}
